import Vue from 'vue'
import Router from 'vue-router'
import example from './example'

const layout = () => import('../components/layout/layout'),
    viewError = () => import('../components/layout/view-error'),
    exampleLayout = () => import('../components/layout/example-layout'),
    layoutShop = () => import('../components/layout/layout-shop'),
    index = () => import('../page/my/index'),
    managerIndex = () => import('../page/manager/index'),
    managerAccount = () => import('../page/manager/account'),
    managerApps = () => import('../page/manager/apps'),
    home = () => import('../page/supermarket/home'),
    pdList = () => import('../page/supermarket/list'),
    pdListDetails = () => import('../page/supermarket/details'),
    managerNotice = () => import('../page/manager/notice'),
    managerNoticeList = () => import('../page/manager/notice-list'),
    application = () => import('../page/manager/application'),
    applicationFrom = () => import('../page/supermarket/application-from'),
    applicationSubmit = () => import('../page/supermarket/application-submit'),
    success = () => import('../page/supermarket/success'),
    authorization = () => import('../page/manager/authorization'),
    selfBuilt = () => import('../page/manager/self-built'),
    selfBuiltAdd = () => import('../page/manager/self-built-add'),
    selfBuiltRevise = () => import('../page/manager/self-built-revise'),
    spManagerAdvisory = () => import('../page/sp-manager/advisory'),
    spManagerAdvisoryDetail = () => import('../page/sp-manager/advisory-detail'),
    spManagerApplication = () => import('../page/sp-manager/application'),
    spManagerApplicationDeatil = () => import('../page/sp-manager/application-detail'),
    appManager = () => import('../page/sp-manager/app-manager'),
    noticeManager = () => import('../page/sp-manager/notice-manager'),
    navManager = () => import('../page/sp-manager/nav-manager'),
    requirementDetails = () => import('../page/manager/requirement-details'),
    history = () => import('../page/manager/history'),
    ipAmendment = () => import('../page/manager/ip-amendment'),
    spAmendment = () => import('../page/sp-manager/sp-amendment'),
    requirementModify = () => import('../page/manager/requirement-modify'),
    ipModification = () => import('../page/manager/ip-modification'),
    spIpModify = () => import('../page/sp-manager/sp-ip-modify'),
    spInform = () => import('../page/sp-manager/sp-inform'),
    navDetails = () => import('../page/sp-manager/nav-details'),
    homeManager = () => import('../page/sp-manager/home-manager'),
    hotProducts = () => import('../page/sp-manager/hot-products'),
    featuredProducts = () => import('../page/sp-manager/featured-products'),
    unitCooperation = () => import('../page/sp-manager/unit-cooperation'),
    appManagerDetail = () => import('../page/sp-manager/app-manager-detail'),
    banner = () => import('../page/sp-manager/banner'),
    hotPdDetail = () => import('../page/sp-manager/hot-detail'),
    featureDetail = () => import('../page/sp-manager/feature-detail'),
    unitDetail = () => import('../page/sp-manager/unit-detail'),
    spManagerSort = () => import('../page/sp-manager/sort'),
    // 初始路由集
    constantRouterMap = [
        {
            path: '/401',
            name: '401',
            component: viewError
        },
        {
            path: '/',
            name: 'index',
            component: layout
        }
    ],
    // 动态路由集
    routes = [
        {
            path: '/my',
            name: 'my',
            component: layout,
            meta: {
                title: '个人后台'
            },
            children: []
        },
        {
            path: '/manager',
            name: 'manager',
            component: layout,
            meta: {
                title: '机构管理员后台'
            },
            children: []
        },
        {
            path: '/sp-manager',
            name: 'sp-manager',
            component: layout,
            meta: {
                title: '超级管理员后台'
            },
            children: []
        },
        {
            path: '/spm',
            name: 'spm',
            component: layoutShop,
            children: [],
            meta: {
                title: '应用超市'
            }
        }
    ],
    // 个人账户
    layoutRouter = [
        {
            name: 'center',
            title: '个人中心',
            path: '/my',
            auth: 'ptGrzx',
            children: [
                {
                    path: 'index',
                    name: 'normalIndex',
                    component: managerIndex,
                    meta: {
                        title: '工作台',
                        parent: 'center',
                        icon: 'workbench',
                        auth: 'ptGzt'
                    },
                    children: [
                        {
                            path: 'noticeList',
                            component: managerNoticeList,
                            meta: {
                                title: '通知列表',
                                parent: 'center',
                                auth: 'ptGzt'
                            },
                            children: [
                                {
                                    path: ':id',
                                    component: managerNotice,
                                    meta: {
                                        title: '通知详情',
                                        parent: 'center',
                                        auth: 'ptGzt'
                                    }
                                }
                            ]
                        },
                        {
                            path: 'noticeDetail/:id',
                            component: managerNotice,
                            meta: {
                                title: '通知详情',
                                parent: 'center'
                            }
                        }
                    ]
                },
                {
                    path: 'account',
                    name: 'account',
                    component: managerAccount,
                    meta: {
                        title: '账户信息',
                        parent: 'center',
                        icon: 'account-info',
                        auth: 'ptZhxx'
                    }
                },
                {
                    path: 'apps',
                    name: 'apps',
                    component: managerApps,
                    meta: {
                        title: '我的应用',
                        parent: 'center',
                        icon: 'apps',
                        auth: 'ptZhxx'
                    }
                }
            ]
        }
    ],
    // 机构管理员账户
    managerRouter = [
        {
            name: 'center',
            title: '个人中心',
            path: '/manager',
            auth: 'jgGrzx',
            children: [
                {
                    path: 'index',
                    name: 'managerIndex',
                    component: managerIndex,
                    meta: {
                        title: '工作台',
                        parent: 'center',
                        icon: 'workbench',
                        auth: 'jgGzt'
                    },
                    children: [
                        {
                            path: 'noticeList',
                            component: managerNoticeList,
                            meta: {
                                title: '通知列表',
                                parent: 'center',
                                auth: 'jgGzt'
                            },
                            children: [
                                {
                                    path: ':id',
                                    component: managerNotice,
                                    meta: {
                                        title: '通知详情',
                                        parent: 'center',
                                        auth: 'jgGzt'
                                    }
                                }
                            ]
                        },
                        {
                            path: 'noticeDetail/:id',
                            component: managerNotice,
                            meta: {
                                title: '通知详情',
                                parent: 'center',
                                auth: 'jgGzt'
                            }
                        }
                    ]
                },
                {
                    path: 'account',
                    name: 'managerAccount',
                    component: managerAccount,
                    meta: {
                        title: '账户信息',
                        parent: 'center',
                        icon: 'account-info',
                        auth: 'jgZhxx'
                    }
                },
                {
                    path: 'selfBuilt',
                    name: 'selfBuilt',
                    component: selfBuilt,
                    meta: {
                        title: '我的自建系统',
                        parent: 'center',
                        icon: 'self-built',
                        auth: 'jgZjxx'
                    },
                    children: [
                        {
                            path: 'add',
                            name: 'selfBuiltAdd',
                            component: selfBuiltAdd,
                            meta: {
                                title: '新增自建系统',
                                auth: 'jgZjxx'
                            }
                        },
                        {
                            path: 'detail/:id',
                            name: 'selfBuiltRevise',
                            component: selfBuiltRevise,
                            meta: {
                                title: '修改自建系统',
                                auth: 'jgZjxx'
                            }
                        }
                    ]
                },
                {
                    path: 'ipAmendment',
                    name: 'ipAmendment',
                    component: ipAmendment,
                    meta: {
                        title: 'IP修改申请单',
                        parent: 'center',
                        icon: 'ip-edit',
                        auth: 'jgIpXgsqd'
                    },
                    children: [
                        {
                            path: 'detail',
                            name: 'ipModification',
                            component: ipModification,
                            meta: {
                                title: '申请详情',
                                parent: 'center',
                                auth: 'jgIpXgsqd'
                            }
                        }
                    ]
                }
            ]
        },
        {
            name: 'app-mgr',
            title: '应用管理',
            path: '/manager',
            auth: 'jgYygl',
            children: [
                {
                    path: 'application',
                    name: 'application',
                    component: application,
                    meta: {
                        title: '需求申请列表',
                        parent: 'app-mgr',
                        icon: 'demand',
                        auth: 'jgXqsqlb'
                    },
                    children: [
                        {
                            path: 'detail',
                            name: 'requirementDetails',
                            component: requirementDetails,
                            meta: {
                                title: '申请详情',
                                parent: 'app-mgr',
                                auth: 'jgXqsqlb'
                            },
                            children: [
                                {
                                    path: 'history',
                                    name: 'requirementHistory',
                                    component: history,
                                    meta: {
                                        title: '历史版本',
                                        parent: 'app-mgr',
                                        auth: 'jgXqsqlb'
                                    }
                                }
                            ]
                        },
                        {
                            path: 'edit',
                            name: 'requirementModify',
                            component: requirementModify,
                            meta: {
                                title: '修改需求单',
                                parent: 'app-mgr'
                            }
                        }
                    ]
                },
                {
                    path: 'demand',
                    name: 'managerApplication',
                    component: spManagerApplication,
                    meta: {
                        title: '需求审核列表',
                        parent: 'app-mgr',
                        icon: 'demand',
                        auth: 'jgXqshlb'
                    },
                    children: [
                        {
                            path: 'detail',
                            name: 'managerApplicationDetail',
                            component: spManagerApplicationDeatil,
                            meta: {
                                title: '申请详情',
                                parent: 'app-mgr',
                                auth: 'jgXqshlb'
                            },
                            children: [
                                {
                                    path: 'history',
                                    name: 'managerApplicationHistory',
                                    component: history,
                                    meta: {
                                        title: '历史版本',
                                        parent: 'app-mgr',
                                        auth: 'jgXqshlb'
                                    }
                                }
                            ]
                        }
                    ]
                },
                {
                    path: 'authorization',
                    name: 'authorization',
                    component: authorization,
                    meta: {
                        title: '权限管理',
                        parent: 'app-mgr',
                        icon: 'permission',
                        auth: 'jgQxgl'
                    }
                },
                {
                    path: 'apps',
                    name: 'managerApps',
                    component: managerApps,
                    meta: {
                        title: '我的应用',
                        parent: 'app-mgr',
                        icon: 'apps',
                        auth: 'jgWdyy'
                    }
                }
            ]
        }

    ],
    // 超级管理员账户
    spManagerRouter = [
        {
            path: '/sp-manager',
            auth: 'spMenu',
            children: [
                {
                    path: 'advisory',
                    name: 'advisory',
                    component: spManagerAdvisory,
                    meta: {
                        title: '用户咨询',
                        icon: 'consult',
                        auth: 'spYhzx'
                    },
                    children: [
                        {
                            path: ':id',
                            name: 'spManagerAdvisoryDetail',
                            component: spManagerAdvisoryDetail,
                            meta: {
                                title: '咨询详情',
                                auth: 'spYhzx'
                            }
                        }
                    ]
                },
                {
                    path: 'application',
                    name: 'sp-Application',
                    component: index,
                    meta: {
                        title: '申请',
                        noJump: true,
                        icon: 'demand',
                        auth: 'spSq'
                    },
                    children: [
                        {
                            path: 'demand',
                            name: 'spApplication',
                            component: spManagerApplication,
                            meta: {
                                title: '需求申请列表',
                                auth: 'spXqsqlb'
                            },
                            children: [
                                {
                                    path: 'detail',
                                    name: 'spApplicationDetail',
                                    component: spManagerApplicationDeatil,
                                    meta: {
                                        title: '申请详情',
                                        auth: 'spXqsqlb'
                                    },
                                    children: [
                                        {
                                            path: 'history',
                                            name: 'spApplicationHistory',
                                            component: history,
                                            meta: {
                                                title: '历史版本',
                                                parent: 'app-mgr',
                                                auth: 'spXqsqlb'
                                            }
                                        }
                                    ]
                                }
                            ]
                        },
                        {
                            path: 'ip-amend',
                            name: 'spAmendment',
                            component: spAmendment,
                            meta: {
                                title: 'IP修改',
                                auth: 'spIpXg'
                            },
                            children: [
                                {
                                    path: 'detail',
                                    name: 'spIpModify',
                                    component: spIpModify,
                                    meta: {
                                        title: '申请详情',
                                        auth: 'spIpXg'
                                    }
                                }
                            ]
                        }
                    ]
                },
                {
                    path: 'app-manager',
                    name: 'appManager',
                    component: appManager,
                    meta: {
                        title: '应用',
                        icon: 'apps',
                        auth: 'spYy'
                    },
                    children: [
                        {
                            path: 'add',
                            name: 'appManagerAdd',
                            component: appManagerDetail,
                            meta: {
                                title: '应用详情',
                                auth: 'spYy'
                            }
                        },
                        {
                            path: ':id',
                            name: 'appManagerDetail',
                            component: appManagerDetail,
                            meta: {
                                title: '应用详情',
                                auth: 'spYy'
                            }
                        }
                    ]
                },
                {
                    path: 'notice-manager',
                    name: 'noticeManager',
                    component: noticeManager,
                    meta: {
                        title: '通知',
                        icon: 'message',
                        auth: 'spTz'
                    },
                    children: [
                        {
                            path: 'add',
                            name: 'spInformAdd',
                            component: spInform,
                            meta: {
                                title: '通知管理详情',
                                auth: 'spTz'
                            }
                        },
                        {
                            path: ':id',
                            name: 'spInformDetail',
                            component: spInform,
                            meta: {
                                title: '通知管理详情',
                                auth: 'spTz'
                            }
                        }

                    ]
                },
                {
                    path: 'sort',
                    name: 'sort',
                    component: spManagerSort,
                    meta: {
                        title: '分类',
                        icon: 'sort',
                        auth: 'spFl'
                    }
                },
                {
                    path: 'system',
                    name: 'system',
                    component: index,
                    meta: {
                        title: '系统',
                        icon: 'system',
                        noJump: true,
                        auth: 'spXt'
                    },
                    children: [
                        {
                            path: 'nav',
                            name: 'navManager',
                            component: navManager,
                            meta: {
                                title: '导航管理',
                                auth: 'spDhgl'
                            },
                            children: [
                                {
                                    path: 'add',
                                    name: 'navAdd',
                                    component: navDetails,
                                    meta: {
                                        title: '导航管理详情',
                                        auth: 'spDhgl'
                                    }
                                },
                                {
                                    path: ':id',
                                    name: 'navDetails',
                                    component: navDetails,
                                    meta: {
                                        title: '导航管理详情',
                                        auth: 'spDhgl'
                                    }
                                }
                            ]
                        },
                        {
                            path: 'homeManager',
                            name: 'homeManager',
                            component: homeManager,
                            meta: {
                                title: '首页管理',
                                auth: 'spSygl'
                            },
                            children: [
                                {
                                    path: 'hotProducts',
                                    name: 'hotProducts',
                                    component: hotProducts,
                                    meta: {
                                        title: '热门产品管理',
                                        auth: 'spSygl'
                                    },
                                    children: [
                                        {
                                            path: 'add',
                                            name: 'hotPdAdd',
                                            component: hotPdDetail,
                                            meta: {
                                                title: '热门产品详情',
                                                auth: 'spSygl'
                                            }
                                        },
                                        {
                                            path: ':id',
                                            name: 'hotPdDetail',
                                            component: hotPdDetail,
                                            meta: {
                                                title: '热门产品详情',
                                                auth: 'spSygl'
                                            }
                                        }
                                    ]
                                },
                                {
                                    path: 'featuredProducts',
                                    name: 'featuredProducts',
                                    component: featuredProducts,
                                    meta: {
                                        title: '产品特色管理',
                                        auth: 'spSygl'
                                    },
                                    children: [
                                        {
                                            path: 'add',
                                            name: 'featureAdd',
                                            component: featureDetail,
                                            meta: {
                                                title: '产品特色详情',
                                                auth: 'spSygl'
                                            }
                                        },
                                        {
                                            path: ':id',
                                            name: 'featureDetail',
                                            component: featureDetail,
                                            meta: {
                                                title: '产品特色详情',
                                                auth: 'spSygl'
                                            }
                                        }
                                    ]
                                },
                                {
                                    path: 'unitCooperation',
                                    name: 'unitCooperation',
                                    component: unitCooperation,
                                    meta: {
                                        title: '合作单位管理',
                                        auth: 'spSygl'
                                    },
                                    children: [
                                        {
                                            path: 'add',
                                            name: 'unitAdd',
                                            component: unitDetail,
                                            meta: {
                                                title: '合作单位详情',
                                                auth: 'spSygl'
                                            }
                                        },
                                        {
                                            path: ':id',
                                            name: 'unitDetail',
                                            component: unitDetail,
                                            meta: {
                                                title: '合作单位详情',
                                                auth: 'spSygl'
                                            }
                                        }
                                    ]
                                },
                                {
                                    path: 'banner',
                                    name: 'banner',
                                    component: banner,
                                    meta: {
                                        title: 'banner 管理',
                                        auth: 'spSygl'
                                    }
                                }
                            ]
                        }
                    ]
                }

            ]
        }
    ],
    // 应用超市
    spmRouter = [
        {
            path: 'home',
            name: 'home',
            component: home,
            meta: {
                title: '应用超市',
                auth: 'yycs'
            }
        },
        {
            path: 'list',
            name: 'pdList',
            component: pdList,
            meta: {
                title: '应用列表',
                auth: 'yycs'
            }
        },
        {
            path: 'applicationFrom',
            name: 'applicationFrom',
            component: applicationFrom,
            meta: {
                title: '资源申请单',
                auth: 'viewSql'
            }
        },
        {
            path: 'detail/:id',
            name: 'pdListDetails',
            component: pdListDetails,
            meta: {
                title: '产品详情',
                auth: 'yycs'
            }
        },
        {
            path: 'applicationSubmit',
            name: 'applicationSubmit',
            component: applicationSubmit,
            meta: {
                title: '资源申请单提交',
                auth: 'viewPostSql'
            }
        },
        {
            path: 'success',
            name: 'success',
            component: success,
            meta: {
                title: '资源申请单成功',
                auth: 'yycs'
            }
        }
    ]

/*
* 开发环境添加example示例路由，可跳转查看组件如何使用
* 上线时将这一段注释
*/
if (process.env.NODE_ENV !== 'production') {
    constantRouterMap.push({
        path: '/example',
        name: 'example',
        component: exampleLayout,
        meta: {
            title: '控件示例'
        },
        children: []
    })
    constantRouterMap[constantRouterMap.length - 1].children.unshift(...example)
}

let router = new Router({
    mode: 'history',
    routes: constantRouterMap
})

// 路由跳转前更改网页标题
router.beforeEach((to, from, next) => {
    // 页面跳转更改浏览器标题
    // if (to.meta && to.meta.title) {
    //     document.title = to.meta.title
    // }
    next()
})

Vue.use(Router)

export default router

export {
    routes,
    layoutRouter,
    managerRouter,
    spManagerRouter,
    spmRouter
}
